package com.itheima.stock.controller;

import com.itheima.stock.common.domain.*;
import com.itheima.stock.pojo.StockBusiness;
import com.itheima.stock.service.StockService;
import com.itheima.stock.vo.resp.PageResult;
import com.itheima.stock.vo.resp.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/quot")
public class StockController {
    @Autowired
    private StockService stockService;

    @GetMapping("/stockBusiness")
    public R<List<StockBusiness>> findAllBusiness(){
        return stockService.findAllBusiness();

    }

    /**
     * 获取国内最新大盘指数
     * @return
     */
    @GetMapping("/index/all")
    public R<List<InnerMarketDomain>> getInnerStockMarket(){
        return stockService.getInnerStockMarket();
    }

    /**
     * 查询最新板块数据前10
     * @return
     */
    @GetMapping("/sector/all")
    public R<List<StockBlockDomain>> getSectorAll(){
        return stockService.getSectorAllLimit();
    }

    /**
     * 沪深两市个股涨幅分时行情数据
     * @return
     */
    @GetMapping("/stock/increase")
    public R<List<StockUpDownDomain>> getUpDownStock(){
        return stockService.getUpDownAllLimit();
    }

    /**
     * 沪深两市个股行情列表查询 ,以时间顺序和涨幅排序分页查询
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/stock/all")
    public R<PageResult<StockUpDownDomain>> getUpDownAllPage(Integer page,Integer pageSize){
        return stockService.getUpDownAllPage(page,pageSize);
    }

    /**
     * 沪深两市涨跌停分时行情数据查询，查询T日每分钟的涨跌停数据
     * @return
     */
    @GetMapping("/stock/updown/count")
    public R<Map> getUpDownCount(){
        return stockService.getUpDownCount();
    }

    /**
     * 涨幅榜数据分页导出到excel
     * @param response
     * @param page
     * @param pageSize
     */
    @GetMapping("/stock/export")
    public void stockExport(HttpServletResponse response,Integer page,Integer pageSize){
        stockService.exportStockExcel(response,page,pageSize);
    }

    /**
     * 统计两市成交量在每分钟的之和的统计
     * @return
     */
    @GetMapping("/stock/tradevol")
    public R<Map> getStockTravolCompare(){
        return stockService.getStockTravolCompare();
    }

    /**
     * 查询当前时间下股票的涨跌幅度区间统计功能
     * @return
     */
    @GetMapping("/stock/updown")
    public R<Map> getStockUpDownScope(){
        return stockService.getStockUpDownScope();
    }

    /**
     * 查询单个个股的分时行情数据，查询时间周期是T日开盘到当前时间
     * @param code
     * @return
     */
    @GetMapping("/stock/screen/time-sharing")
    public R<List<StockScreenMinDomain>> getStockScreenMinuteSharing(String code){
        return stockService.getStockScreenMinuteSharing(code);
    }

    /**
     * 单个个股日K 数据查询 ，可以根据时间区间查询数日的K线数据
     * @param code
     * @return
     */
    @GetMapping("/stock/screen/dkline")
    public R<List<StockScreenDayDomain>> getDayKLinData(String code){
        return stockService.getDayKLinData(code);
    }
}
